package cn.doctor.assistant.pad.ui.ziliao;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import cn.doctor.assistant.pad.R;
import cn.doctor.assistant.pad.base.BaseNetActivity;
import cn.doctor.assistant.pad.entity.Course;
import cn.doctor.assistant.pad.entity.CourseResBean;
import cn.doctor.assistant.pad.entity.Record;
import cn.doctor.assistant.pad.ui.UI;
import cn.doctor.assistant.pad.ui.common.ImageGridAdapter;

/**
 * Created by jiaolf on 2016/4/1.
 */
public class BingChengDetailActivity extends BaseNetActivity {

    @InjectView(R.id.titlebar_left_title)
    TextView titlebarLeftTitle;
    @InjectView(R.id.icon)
    ImageView icon;
    @InjectView(R.id.text_name)
    TextView textName;
    @InjectView(R.id.text_doctor)
    TextView textDoctor;
    @InjectView(R.id.text_record_date)
    TextView textRecordDate;
    @InjectView(R.id.text_note)
    TextView textNote;
    @InjectView(R.id.gird_images)
    GridView gridImages;

    ImageGridAdapter mGridAdapter;

    Course course; // 病程记录
    Record record; // 住院记录

    List<String> imgs = new ArrayList<>(); // 病例图片

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bingcheng_detail);
        ButterKnife.inject(this);
        setTitle("病程记录详情");
        course = (Course) getIntent().getExtras().getSerializable("course");
        record = (Record) getIntent().getExtras().getSerializable("record");
        initialize();
    }

    void initialize() {
        if (course.getPictures() != null && course.getPictures().size() > 0) {
            for(CourseResBean c : course.getPictures()) {
                imgs.add(c.getPicture());
            }
        }

        textName.setText(record.getName());
        textDoctor.setText("主治医生：" + record.getMajor());

        textRecordDate.setText("记录日期：" + course.getDate());
        textNote.setText(course.getContent());

        mGridAdapter = new ImageGridAdapter(this, imgs);
        gridImages.setAdapter(mGridAdapter);
        mGridAdapter.setGridView(gridImages);
        mGridAdapter.setDone(true); // 设置为完成状态，不可上传图片
        gridImages.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                UI.showBigImage(imgs.get(position));
            }
        });
    }

    @OnClick(R.id.titlebar_left_title)
    public void onClick() {
        back();
    }
}
